package com.tanhua.dubbo.api.mongo;

import com.tanhua.model.mongo.Personality;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class PersonalityApiImpl implements PersonalityApi{

    @Autowired
    private MongoTemplate mongoTemplate;
    /**
     * 根据报告id查询灵魂人格表得到Personality对象
     *
     * @param reportId
     * @return
     */
    @Override
    public Personality findPersonalityById(String reportId) {
        return mongoTemplate.findById(reportId,Personality.class);
    }

    /**
     * 根据人格类型查询灵魂人格表
     *
     * @param personalityType
     * @return
     */
    @Override
    public Personality findPersonalityByType(Integer personalityType) {
        Query query = new Query();
        query.addCriteria(Criteria.where("personalityType").is(personalityType));
        return  mongoTemplate.findOne(query,Personality.class);
    }
}
